package com.example.image.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class AdapterImage extends BaseAdapter {
	private Context context;
	private ArrayList<Bitmap> list;
	private int width;

	public AdapterImage(Context context, int width) {
		this.context = context;
		this.list = new ArrayList<Bitmap>();
		this.width = width / 3;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Bitmap getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView iv = new ImageView(context);
		iv.setAdjustViewBounds(true);
		iv.setLayoutParams(new LayoutParams(width, width));
		iv.setImageBitmap(getItem(position));
		return iv;
	}

	public void add(Bitmap[] values) {
		for (Bitmap bitmap : values) {
			list.add(bitmap);
		}
		notifyDataSetChanged();
	}

}
